import { invoke } from "@tauri-apps/api/core";
interface ColorRgba {
    r: number;
    g: number;
    b: number;
    a?: number;
}
class CTauriInvoker {
    async openPath(path: string) {
        await invoke('open_path', { uri: path });
    }

    async setBarColor(color: ColorRgba, label: string = '') {
        await invoke('set_bar_color', {
            colorRgba: {
                r: color.r,
                g: color.g,
                b: color.b,
                a: color.a ?? 1
            },
            label
        });
    }

    async getMetar(airports: string[]): Promise<string> {
        return await invoke('get_metar', { airport: airports.join(',') });
    }

    async unzipFile(filePath: string, targetPath: string) {
        await invoke('unzip_file', { path: filePath, target: targetPath });
    }

    async createWindow(config: IWindowParam) {
        await invoke('create_window', {
            label: config.label,
            url: config.url,
            width: config.width ?? 800,
            height: config.height ?? 600,
            title: config.title ?? config.label
        });
    }
}
interface IWindowParam {
    label: string;
    url: string;
    width?: number;
    height?: number;
    title?: string;
}

export const TauriInvoker = new CTauriInvoker();